package com.haidechizi.leetcode;

/**
 * @author: wangdejun
 * @create: 2020-04-13 12:01
 **/
public class _849_到最近的人的最大距离 {

    public int maxDistToClosest(int[] seats) {
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < seats.length; i++) {
            if (seats[i] == 0) {
                max = Math.max(getMinDistance(seats, i), max);
            }
        }
        return max;
    }

    public int getMinDistance(int[] seats, int index) {
        int min1 = Integer.MAX_VALUE;
        int min2 = Integer.MAX_VALUE;
        for (int i = 0; i < index; i++) {
            if (i == index) {
                continue;
            }
            if(seats[i] == 1) {
                min1 = index - i;
            }
        }
        for (int i = seats.length - 1; i > index; i--) {
            if (i == index) {
                continue;
            }
            if(seats[i] == 1) {
                min2 = i - index;
            }
        }
        return Integer.min(min1, min2);
    }

    public static void main(String[] args) {
        new _849_到最近的人的最大距离().maxDistToClosest(new int[]{1,0,0,0,1,0,1});
    }

}
